home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / test / test10.c < prev    next >
C/C++ Source or Header  |  1990-07-23  |  2KB  |  121 lines

  1. /* test 10 */
  2.  
  3. #include <sys/types.h>
  4. #include <fcntl.h>
  5. #include <stdio.h>
  6.  
  7. char *name[] = {"t10a", "t10b", "t10c", "t10d", "t10e", "t10f", "t10g", "t10h", "t10i", "t10j"};
  8.  
  9. extern int errno;
  10. int errct;
  11. long prog[300];
  12. int psize;
  13.  
  14. main()
  15. {
  16.   int i, n, pid;
  17.  
  18.   printf("Test 10 ");
  19.   fflush(stdout);        /* have to flush for child's benefit */
  20.   pid = getpid();
  21.  
  22.   /* Create files t10b ... t10h */
  23.   mkfiles();
  24.  
  25.   if (getpid() == pid)
  26.     if (fork() == 0) {
  27.         execl("t10a", (char *) 0);
  28.         exit(0);
  29.     }
  30.   if (getpid() == pid)
  31.     if (fork() == 0) {
  32.         execl("t10b", (char *) 0);
  33.         exit(0);
  34.     }
  35.   if (getpid() == pid)
  36.     if (fork() == 0) {
  37.         execl("t10c", (char *) 0);
  38.         exit(0);
  39.     }
  40.   if (getpid() == pid)
  41.     if (fork() == 0) {
  42.         execl("t10d", (char *) 0);
  43.         exit(0);
  44.     }
  45.   for (i = 0; i < 60; i++) {
  46.     spawn(rand() & 07);
  47.   }
  48.   for (i = 0; i < 4; i++) wait(&n);
  49.   if (errct == 0)
  50.     printf("ok\n");
  51.   else
  52.     printf(" %d errors\n", errct);
  53.   rmfiles();
  54.   exit(0);
  55. }
  56.  
  57. spawn(n)
  58. int n;
  59. {
  60.   int pid, k;
  61.  
  62.   if (pid = fork()) {
  63.     wait(&n);        /* wait for some child (any one) */
  64.   } else {
  65.     k = execl(name[n], (char *) 0);
  66.     errct++;
  67.     printf("Child execl didn't take. file=%s errno=%d\n", name[n], errno);
  68.     rmfiles();
  69.     exit(0);
  70.     printf("Worse yet, EXIT didn't exit\n");
  71.   }
  72. }
  73.  
  74. mkfiles()
  75. {
  76.   int fd;
  77.   fd = open("t10a", 0);
  78.   if (fd < 0) {
  79.     printf("Can't open t10a\n");
  80.     exit(1);
  81.   }
  82.   psize = read(fd, prog, 300 * 4);
  83.   cr_file("t10b", 1600);
  84.   cr_file("t10c", 1400);
  85.   cr_file("t10d", 2300);
  86.   cr_file("t10e", 3100);
  87.   cr_file("t10f", 2400);
  88.   cr_file("t10g", 1700);
  89.   cr_file("t10h", 1500);
  90.   cr_file("t10i", 4000);
  91.   cr_file("t10j", 2250);
  92.   close(fd);
  93. }
  94.  
  95.  
  96. cr_file(name, size)
  97. char *name;
  98. int size;
  99.  
  100. {
  101.   int fd;
  102.  
  103.   prog[6] = (long) size;
  104.   fd = creat(name, 0755);
  105.   write(fd, prog, psize);
  106.   close(fd);
  107. }
  108.  
  109. rmfiles()
  110. {
  111.   unlink("t10b");
  112.   unlink("t10c");
  113.   unlink("t10d");
  114.   unlink("t10e");
  115.   unlink("t10f");
  116.   unlink("t10g");
  117.   unlink("t10h");
  118.   unlink("t10i");
  119.   unlink("t10j");
  120. }
  121.